export const isArray = (obj) => Object.prototype.toString.call(obj)==="[object Array]";
export const isObject = (obj) => Object.prototype.toString.call(obj)==="[object Object]";

export const _extend = (current, target) => {
  if (!isObject(current)) return target;
  if (!isObject(target)) return current;
  if (!isObject(current) && !isObject(target)) return {};
  if (JSON.stringify(target) === "{}") return current;
  const tempCurrent = JSON.parse(JSON.stringify(current));
  for (let key in target) {
    const data = target[key];
    if (!tempCurrent.hasOwnProperty(key)) {
      tempCurrent[key] = data;
    } else {
      if (isArray(data)) {
        let tempArr = [];
        data.forEach((list) => {
          const currentData = {
            ...tempCurrent[key][0],
            ...list,
          };
          tempArr.push(currentData);
        });
        tempCurrent[key] = tempArr;
      } else {
        tempCurrent[key] = {
          ...tempCurrent[key],
          ...data,
        };
      }
    }
  }
  return tempCurrent;
};
